package servlet;



import util.JdbcUtil;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.PreparedStatement;

public class WarehouseaddServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int wid =Integer.parseInt(request.getParameter("wid"));
        String wname =request.getParameter("wname");
        String wperson =request.getParameter("wperson");
        String addrss =request.getParameter("addrss");
        String statics =request.getParameter("statics");
        String sql ="INSERT INTO warehouse VALUES (?,?,?,?,?)";
        PreparedStatement ps;
        try {
            ps = JdbcUtil.getConnection().prepareStatement(sql);
            ps.setInt(1,wid);
            ps.setString(2, wname);
            ps.setString(3, wperson);
            ps.setString(4, addrss);
            ps.setString(5, statics);
            int up = ps.executeUpdate();
            if(up==1){
                request.getRequestDispatcher("warehouse.jsp").forward(request, response);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }



    }
}
